package com.clstu.homeworks;

import com.clstu.super_.B;

public class HomeWork05 {
    public static void main(String[] args) {
        SavingAccount cou = new SavingAccount(1000);
        cou.depost(100);//免手续
        cou.depost(100);//免手续
        cou.depost(100);//免手续
        cou.depost(100);
        System.out.println(cou.getBalance());
        cou.withdraw(100);
        System.out.println(cou.getBalance());
        cou.earnMonthlyInterest();//重置可免手续次数
        System.out.println(cou.getBalance());
        cou.depost(500);//免手续
        System.out.println(cou.getBalance());
    }
}
class BankAccount{
    private double balance;

    public BankAccount(int balance) {
        this.balance = balance;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(int balance) {
        this.balance = balance;
    }

    //存款
    public void depost(double amount){
        balance+=amount;
    }

    public void withdraw(double amount){
        balance-=amount;
    }
}

class CheckingAccount extends BankAccount{
    public CheckingAccount(int balance) {
        super(balance);
    }

    @Override
    public void depost(double amount) {
        super.depost(amount-1);

    }

    @Override
    public void withdraw(double amount) {
        super.withdraw(amount+1);
    }
}

class SavingAccount extends BankAccount {
    private double rate=0.1;
    private int count=3;
    public SavingAccount(int balance) {
        super(balance);
    }

    @Override
    public void depost(double amount) {
        if(count>0)
            super.depost(amount);
        else
            super.depost(amount-1);
        count--;
    }

    @Override
    public void withdraw(double amount) {
        if(count>0)
           super.withdraw(amount);
        else
            super.withdraw(amount+1);
        count--;
    }

    public void earnMonthlyInterest(){
        super.depost(getBalance()*rate);
        count=3;
    }
}